package com.nineclock.system.easyexcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.List;

public class MemberParseListener extends AnalysisEventListener<ExcelMember> {
    private SysCompanyUserService companyUserService;
    public MemberParseListener(SysCompanyUserService companyUserService) {
        this.companyUserService = companyUserService;
    }

    private List<ExcelMember> list = new ArrayList<>();
    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        //把每一行对应的对象添加到集合中
        list.add(data);
    }


    @SneakyThrows
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        //读取完成后执行
        companyUserService.importData(list);
    }
}
